import type {
  WebGLRenderer,
  Clock,
  Scene,
  TextureLoader,
  PerspectiveCamera,
  Object3D,
  sRGBEncoding,
  Texture,
  Color,
} from "three";
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
import type { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";

export interface Deps {
  clock: Clock;
  scene: Scene;
  gltfLoader: GLTFLoader;
  renderer: WebGLRenderer;
  camera: PerspectiveCamera;
  textureLoader: TextureLoader;
}

export abstract class publicThreeClass {
  deps: Deps;
  private _objects: Object3D[] = [];
  orbitControl?: OrbitControls;
  private _cameraObjects = [];

  abstract init(): Promise<void>;
  abstract update(): void;
  abstract dispose(): void;
  constructor(deps: Deps) {
    this.deps = deps;
  }
  // 添加元素
  add(obj: Object3D) {

    this._objects.push(obj);
    this.deps.scene.add(obj);
  }
  // 添加视角
  addCamera(obj: Object3D) {
    // this._cameraObjects.push(obj);
    // this.deps.camera.add(obj);
  }
  // 清空
  reset() {}

  addControl() {
    try {
      const { camera, renderer } = this.deps;

      this.orbitControl = new OrbitControls(camera, renderer.domElement);
      this.orbitControl.enableDamping = true;
      this.orbitControl.dampingFactor = 0.05;
      this.orbitControl.addEventListener('change', function () {
        // 浏览器控制台查看相机位置变化
     //   console.log('camera.position',camera.position);
    });
    } catch (err) {
      console.log("执行错误");
      console.log(err);
    }
  }
}
